package ylg.cn.com.welecome.littlered.view;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

/**
 * Created by Administrator on 2017/11/13.
 */

public abstract class LoginAnimImageBaseFragment extends Fragment {

    public final int BITMAP_SCROLL = 11;

    public final int BITMAP_SHIELD = 12;

    public float mAnimStartY = -1;

    public int mScrollBitmapHeight = 0;

    public int mNewScrollBitmapHeight = 0;

    public int mImageViewWidth = 0;
    //动画集合;
    public AnimatorSet mAnimatorSet;
    //一个属性动画;
    public ObjectAnimator mObjectAnimator;

    float mScaleWidth = 0;

    float mScaleHeight = 0;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int parentViewWidth =DisplayUtil.getDisplayWidthPixels(getActivity()) - DisplayUtil.dip2px(getActivity(), 40);
        mImageViewWidth = parentViewWidth - DisplayUtil.dip2px(getActivity(),60);
    }

    //获得图片的大小 ;
    public Bitmap bitmapScale(int ivWidth, Bitmap bitmap, int type){
        //拿到bitmap的宽度和高度
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        //新的宽度;
        int newWidth = ivWidth;
        //给据比例拿到新的高度;
        int newHeight = (int) ((float)height) * newWidth / width;
        if(type == BITMAP_SCROLL){
            mNewScrollBitmapHeight = newHeight;
        }
        mScaleWidth = ((float) newWidth) / width;
        mScaleHeight = ((float) newHeight) / height;
        Matrix matrix = new Matrix();
        matrix.postScale(mScaleWidth, mScaleHeight);
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,height, matrix, true);
        return resizedBitmap;
    }

    public void playInAnim(){};

    public void playOutAnim(){};

    public void reset(){};

}
